package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.forbidden.UserForbiddenAdminDTO;
import com.qumitech.visualnovel.controller.vo.forbidden.UserForbiddenVO;
import com.qumitech.visualnovel.service.forbidden.UserForbiddenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author :  ZhChNing
 * @Descriptiom :
 * @Date Created in 2019/7/1 19:05
 */

@RestController
@RequestMapping("/api/user")
public class ForbiddenController {

    @Autowired
    private UserForbiddenService userForbiddenService;


    @GetMapping("/forbidden")
    public BaseRsp listUserForbidden(@RequestParam(value = "uid", required = false) Long uid,
                                     @RequestParam(value = "forbidden_id", required = false) String forbiddenId,
                                     @RequestParam(value = "forbidden_type", required = false) Byte forbiddenType,
                                     @RequestParam(value = "forbidden_value", required = false) String forbiddenValue,
                                     @RequestParam(value = "exist_limit_time", required = false) Byte existLimitTime,
                                     @RequestParam(value = "state", required = false) Byte state,
                                     @RequestParam(value = "offset", defaultValue = "0") Integer offset,
                                     @RequestParam(value = "limit", defaultValue = "20") Integer limit,
                                     @RequestParam(value = "startTime", required = false) String startTime,
                                     @RequestParam(value = "endTime", required = false) String endTime
    ) {
        return new BaseRsp(ResultEnum.SUCCESS, userForbiddenService.listUserForbidden(uid, forbiddenId, forbiddenType, forbiddenValue, existLimitTime, state, offset, limit, startTime, endTime));
    }


    @PostMapping("/forbidden")
    public BaseRsp addUserForbidden(@RequestBody UserForbiddenVO userForbiddenVO) {
        userForbiddenService.addUserForbidden(userForbiddenVO);
        // riskUserAlarmService.forbiddenUser(userForbiddenVO.getUid());
        return new BaseRsp(ResultEnum.SUCCESS);
    }


    @PutMapping("/forbidden/{forbidden_id}")
    public BaseRsp updateUserForbidden(@PathVariable(name = "forbidden_id") String forbiddenId, @RequestBody UserForbiddenVO userForbiddenVO) {
        userForbiddenVO.setForbiddenId(forbiddenId);
        userForbiddenService.updateUserForbidden(userForbiddenVO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }


    @DeleteMapping("/forbidden/{forbidden_id}")
    public BaseRsp removeUserForbidden(@PathVariable(name = "forbidden_id") String forbiddenId) {
        userForbiddenService.removeUserForbidden(forbiddenId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }


    @PostMapping("/forbidden/batch")
    public BaseRsp batchAddUserForbidden(@RequestBody UserForbiddenAdminDTO adminDTO) {
        // riskUserAlarmService.forbiddenUsers(adminDTO.getUids());
        return userForbiddenService.batchAddUserForbidden(adminDTO);
    }
}
